<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="card" >
        <div class="card-header">修改个人信息  <small id="modify-info" class="text-danger"> </small></div>
        <div class="card-body">
            <div class="input-group mb-3">
                <div class="input-group-prepend">
                    <span class="input-group-text">账号</span>
                </div>
                <input id="u_id" name="id" type="text" class="form-control" placeholder="账号" value="${person.id}" readonly="readonly">
            </div>
            <div class="input-group mb-3">
                <div class="input-group-prepend">
                    <span class="input-group-text">名字</span>
                </div>
                <input id="u_name" name="name" type="text" class="form-control" placeholder="名字" value="${person.name}">
            </div>
            <div class="input-group mb-3">
                <div class="input-group-prepend">
                    <span class="input-group-text">密码</span>
                </div>
                <input id="u_pwd" name="password" type="password" class="form-control" placeholder="密码" value="${person.password}">
            </div>
        </div>
        <div class="card-footer">
            <input type="button" onclick="modify()" class="btn btn-outline-primary justify-content-center" value="修改">
            <hr/>
            <button class="btn btn-danger" onclick="deleteUser()">删除账户</button>
        </div>
    </div>

<script>
    function modify() {
        $.ajax({
            url: "${pageContext.request.contextPath}/user/modify",
            type: 'POST',
            data: {"id":$("#u_id").val(),"name":$("#u_name").val(), "password":$("#u_pwd").val()},
            dataType:'json',
            success: function (data) {
                if (data["result"] === 1) {
                    $("#modify-info").text(data['info']);
                    setTimeout(function () {
                        $("#modify-info").text("");
                    }, 3000);
                }
            }
        });
    }
    function deleteUser() {
        $.ajax({
            url:"${pageContext.request.contextPath}/user/destroy",
            type: 'POST',
            data: {"id":${person.id}},
            dataType:'json',
            success:function (data) {
                if (data["result"] === 1) {
                    $("#modify-info").text(data['info']);
                    setTimeout(function () {
                        parent.location="${pageContext.request.contextPath}"
                    }, 500);
                }
            }
        });
    }
</script>
</body>
</html>
